<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<link rel="stylesheet" media="screen" href="css/docs.css" />
<link rel="stylesheet" media="screen"
	href="lib/jqplot/jquery.jqplot.min.css" />
<!-- jQplot SETUP -->
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/jqplot/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="lib/jqplot/jquery.jqplot.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.highlighter.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.pointLabels.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.pieRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.donutRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.bubbleRenderer.min.js"></script>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />


<h1 class="page-title">${listTitle}</h1>
<%@include file="/WEB-INF/pages/exam/exam_common_period.jsp"%>
<section id="section_body"></section>
<s:if test="#request.module == 'qual_sc'">
	<div class="container_12 clearfix leading" style="margin-top: 0px">
		<section class="tabs grid_6 leading">

			<header>
				<h3>未打分</h3>
			</header>
			<ul class="clearfix">

			</ul>
			<section>
				<section class="clearfix" style="display: block;">
					<header></header>
					<div id="list_content_no_score" class="clearfix">暂无未打分数据</div>
				</section>
			</section>
		</section>
		<section class="tabs grid_6 leading">
			<header>
				<h3>已打分</h3>
			</header>
			<ul class="clearfix">

			</ul>
			<section>
				<section class="clearfix" style="display: block;">
					<header></header>
					<div id="list_content_has_score" class="clearfix">暂无已打分数据</div>
				</section>
			</section>
		</section>

		<div class="tabs side grid_12 leading">

			<div class="clear"></div>
		</div>
	</div>
	
	<div style="padding-left: 20px" class="container_12 clearfix leading">
	<div class="form-action clearfix">
			<p>
				<a href="javascript:void(0)" class="button" onclick="postGenerateSubmit()"><span class="icon"
					style="background: url(${ctx}/images/img/page_edit.png)">&nbsp;</span>普通提交</a>
	
				<a class="button" href="javascript:void(0)" onclick="redirectSpeical()"><span
					style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>特别审批提交</a>
			</p>
		</div>
	</div>
</s:if>
<s:elseif test="#request.module == 'qual_as'">
	<div class="container_12 clearfix leading" style="margin-top: 0px">
	<section class="tabs side grid_12 leading" id="qualsetdist_layout">
	</section>
	<div class="tabs side grid_12 leading">

	<div class="clear"></div>
	</div>
</div>

<div style="padding-left: 20px" class="container_12 clearfix leading">
	<div class="form-action clearfix">
		<p>
			<a id="g_clk" href="javascript:void(0)" class="button" onclick="postGenerateSubmit()"><span class="icon"
				style="background: url(${ctx}/images/img/page_edit.png)">&nbsp;</span>普通提交</a>

			<a id="s_clk" class="button" href="javascript:void(0)" onclick="postSpeicalSubmit()"><span
				style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span><span id="s_text">特别审批提交</span></a>
		</p>
	</div>
</div>
</s:elseif>

<script type="text/javascript">
	var isAccordDist = null;
	var isAllowGenerateCommit = null;
	function loadControlPage(url){
		if($("#sel_periodtype").val().trim() == "none"){
			alert("请选择打分周期类型");
			return;
		}
		if(currentSelOrgId <= 0){
			alert("请选择打分部门");
			return;
		}
        var data = {"organizationId":currentSelOrgId, 
        		"type":$("#sel_periodtype").val(), 
        		"periodDesc":$("#sel_period").val()
        		};
        
		$.ajax(url, {
            type:"POST",
            data:data,
            dataType:"html",
            cache:false,
            success:function (a) {
                var obj = $("#section_body");
                obj.html("");
                obj.append(a);
            },
            complete:function () {
            }
        });
		
		//检测是否需要加载额外内容
		<s:if test="#request.module == 'qual_sc'">
			loadListContent('/exam/qual_no_score_list.xhtml');	//加载未打分
			loadListContent('/exam/qual_has_score_list.xhtml');	//加载已打分
		</s:if>
		<s:elseif test="#request.module == 'qual_as'">
			loadQualDist();
		</s:elseif>
	}
	
	function loadListContent(url) {
		var data = {"organizationId":currentSelOrgId, 
				"type":$("#sel_periodtype").val(), 
        		"periodDesc":$("#sel_period").val()
        		};
        //refreshListContent(url, data);
        $.ajax(url, {
            type:"POST",
            //data:{"organizationId":organizationId},
            data:data,
            dataType:"html",
            cache:false,
            success:function (a) {
            	var obj = null;
            	if(url.indexOf('qual_no_score_list') > -1){
                	obj = $("#list_content_no_score");
            	}else{
            		obj = $("#list_content_has_score");
            	}
                obj.html("");
                obj.append(a);
            },
            complete:function () {
            }
        });
    }
	
	function loadQualDist(){
		var url = "/exam/qualset_dist.xhtml";
		var data = {"organizationId":currentSelOrgId,"periodType":$("#sel_periodtype").val()};
        //refreshListContent(url, data);
        $.ajax(url, {
            type:"POST",
            //data:{"organizationId":organizationId},
            data:data,
            dataType:"html",
            cache:false,
            success:function (a) {
            	var obj = $("#qualsetdist_layout");
                obj.html("");
                obj.append(a);
                eval(obj.find("a.current").attr("onclick"));
            },
            complete:function () {
            }
        });
	}
	
	function postGenerateSubmit(){
		if(isAccordDist == null){
			alert("请选定指定周期后在全部提交");
			return;
		}
		if(!isAccordDist){
			alert("现在打分不符合强制性分布，请重新打分在全部提交");
			return;
		}
		var url = "/exam/post_generatesubmit.xhtml";
		var data = {"organizationId":currentSelOrgId, 
				"type":$("#sel_periodtype").val(), 
        		"periodDesc":$("#sel_period").val()        		
        		};
        //refreshListContent(url, data);
        $.ajax(url, {
            type:"POST",
            //data:{"organizationId":organizationId},
            data:data,
            dataType:"html",
            cache:false,
            success:function (res) {
            	if(res != null){
            		if(res == "NORMAL"){
            			alert("操作成功");
            		}else if(res == "COMMITED"){
            			alert("已提交过了，不要重复提交");
            		}else{
            			alert("当前你无权操作");
            		}
            	}
            	//检测是否需要加载额外内容
        		<s:if test="#request.module == 'qual_sc'">
        			loadListContent('/exam/qual_no_score_list.xhtml');	//加载未打分
        			loadListContent('/exam/qual_has_score_list.xhtml');	//加载已打分
        		</s:if>
        		<s:elseif test="#request.module == 'qual_as'">
        			loadQualDist();
        		</s:elseif>
            },
            complete:function () {
            }
        });
	}
	
	function redirectSpeical(){
		if(isAccordDist == null){
			alert("请选定指定周期后在全部提交");
			return;
		}
		/* if(!isAccordDist){
			alert("现在打分不符合强制性分布，请特批打分在通过后提交");
			return;
		} 
		
		 var data = {"organizationId":currentSelOrgId, 
        		"type":$("#sel_periodtype").val(), 
        		"periodDesc":$("#sel_period").val()
        		};
		*/
		window.location.href = "#exam/exam_score.xhtml?p=qual_as&organizationId=" + currentSelOrgId + "&type=" + $("#sel_periodtype").val() + "&periodDesc=" + $("#sel_period").val();
	}
	
	function postSpeicalSubmit(){
		if(isAccordDist == null){
			alert("请选定指定周期后在全部提交");
			return;
		}
		/* if(!isAccordDist){
			alert("现在打分不符合强制性分布，请特批打分在通过后提交");
			return;
		} */
		
		var url = "/exam/post_specialsubmit.xhtml";
		var data = {"organizationId":currentSelOrgId, 
				"type":$("#sel_periodtype").val(), 
        		"periodDesc":$("#sel_period").val()       		
        		};
        //refreshListContent(url, data);
        $.ajax(url, {
            type:"POST",
            //data:{"organizationId":organizationId},
            data:data,
            dataType:"html",
            cache:false,
            success:function (res) {
            	if(res != null){
            		if(res == "NORMAL"){
            			alert("操作成功");
            		}else if(res == "COMMITED"){
            			alert("已提交过了，不要重复提交");
            		}else if(res == "NOREQUEST"){
            			alert("没有需要特批的对象");
            		}else if(res == "NOAUDITEND"){
            			alert("你还存在审核的员工,暂不能特批提交");
            		}else if(res == "NONORMAL"){
            			alert("当前不符合强制性分布，不能提交");
            		}else{
            			alert("当前你无权操作或存在审核的员工");
            		}
            	}
            	loadQualDist();
            },
            complete:function () {
            }
        });
	}
	
	function loadQualDistListContent(eventObj,qsId,startScore,endScore){
		$(eventObj).parent().parent().find("a").removeClass("current");
		$(eventObj).addClass("current");
		var url = "/exam/qual_dist_score_list.xhtml";
		var data = {"organizationId":currentSelOrgId, 
				"type":$("#sel_periodtype").val(), 
        		"periodDesc":$("#sel_period").val(),
        		"startScore":startScore,
        		"endScore":endScore        		
        		};
        //refreshListContent(url, data);
        $.ajax(url, {
            type:"POST",
            //data:{"organizationId":organizationId},
            data:data,
            dataType:"html",
            cache:false,
            success:function (a) {
            	$("#list_content_" + qsId).parent().find("section").attr("style","display:none");
            	var obj = $("#list_content_" + qsId);
            	obj.attr("style","display:block");
                obj.html("");
                obj.append(a);
            },
            complete:function () {
            }
        });
	}
</script>